package com.homedo.odin.solution.enumcode.basic;


import java.util.Arrays;
import lombok.Getter;

@Getter
public enum DownloadCollectEnum {

    DOWNLOAD(1, "下载"),
    COLLECTION(2, "收藏");

    private Integer dbValue;
    private String displayValue;

    DownloadCollectEnum(Integer key, String value) {
        this.displayValue = value;
        this.dbValue = key;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(DownloadCollectEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(DownloadCollectEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(DownloadCollectEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }

}
